<?php
/**
 * 验证
 */

namespace Common\Controller\Api;

use Common\Model\LoginLogModel;
use Common\Model\MemberModel;
use Common\Model\MemberOtherPlatformModel;
use Common\Model\MemberOtherQqModel;
use Common\Model\MemberOtherWeiboModel;
use Common\Model\TarentoModel;
use Think\Controller;

class SignController extends Controller
{

    static public $shop_id;

    public function __construct()
    {
        parent::__construct();

        $this->is_shop();

    }
    /**
     * 检查是否有店铺id
     */
    public function is_shop()
    {

        $shop_id = I('param.shop_id');
        if(empty($shop_id)){
            $shop_id = 14441;
        }

        self::$shop_id = $shop_id;
        $member_id = session('member_id');
        if(empty($member_id)){
            $token = I('post.token');
            if(!empty($token)){
                $id = authcode($token,'DECODE');
                if($id){
                    if(strpos($id,'-')){
                        $users = explode('-',$id);
                        if($users[0]=='qq'){
                            $model = new MemberOtherQqModel();
                            $member_info = $model->where("id={$users[1]}")->find();
                        }
                        if($users[0]=='weibo'){
                            $model = new MemberOtherWeiboModel();
                            $member_info = $model->where("id={$users[1]}")->find();
                        }
                        if($users[0]=='weixin'){
                            $model = new MemberOtherPlatformModel();
                            $member_info = $model->where("id={$users[1]}")->find();
                        }
                        if(empty($member_info)){
                            $this->ajaxReturn(['code'=>301,'msg'=>'token错误']);
                        }
                    }else{
                        $t_model = new TarentoModel();
                        $member_info = $t_model->where("member_id=$id")->find();
                        if(empty($member_info)){
                            $this->ajaxReturn(['code'=>301,'msg'=>'token错误']);
                        }
                        $logModel = new LoginLogModel();
                        $logModel->add(['member_id'=>$id,'ip'=>get_client_ip(),'create_time'=>date('Y-m-d H:i:s',time())]);
                    }

                    session('member_id',$id);
                }
            }

        }
    }
}
